package fr.compil.tab.ihm;

import java.awt.Button;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;

import fr.compil.tab.logic.CellManager;
import fr.compil.tab.model.Board;

public class Tableur extends JPanel{
	
	private JTable table;
	private TableModel model;
	private char headerValue;
	private String formule;
	private Border tabBorder;
	
	public Tableur(int x, int y, Board board){
		this.model =  new TableModel(board);
		table = new JTable(x,y);
		CellManager c = new CellManager(table, board);

		headerValue = 'A';
		for(int i = 1 ; i < table.getColumnCount() ; i++){
			table.setValueAt(headerValue, 0, i);
			headerValue++;
		}
		
		//Initialiser les entetes
		for(int i = 1 ; i < table.getRowCount() ; i++){
			table.setValueAt(i, i, 0);
		}
		headerValue = 'A';
		for(int i = 1 ; i < table.getColumnCount() ; i++){
			table.setValueAt(headerValue, 0, i);
			headerValue++;
		}
		

		//Test de rendu
		table.setDefaultRenderer(table.getColumnClass(0), new Renderer());
		
		this.add(table);
		
	}
	
	public String getSelection(){
		
		int column, row;
		column = table.getSelectedColumn();
		row = table.getSelectedRow();
		
		return ("" + column + row);
		
	}
	

	
	public String getFormule(){
		return formule;
	}
	
	public JTable getTable(){
		return table;
	}

}

